package com.midele.goodstuff.ui.component

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
import androidx.constraintlayout.compose.ConstraintLayout
import com.midele.goodstuff.R
import com.midele.goodstuff.ui.theme.Black12

@Composable
fun CommConfirmDialog(
    title: String,
    content: String,
    onDismissRequest: () -> Unit,
    onConfirmation: () -> Unit,
) {
    Dialog(onDismissRequest = { onDismissRequest() }) {

        ConstraintLayout(modifier = Modifier
            .width(275.dp)
        ){
            Image(
                painter = painterResource(id = R.drawable.ic_dialog_bg), // 替换为你的图片资源ID
                contentDescription = "Logo Image", // 图片描述，对于无障碍很重要
                contentScale = ContentScale.Fit, // 图片填充模式，根据你的需求选择合适的模式
            )

            val (dialogTitle, dialogContent, dialogBtnLayout) = createRefs()

            Text(
                text = title,
                color = Color.White,
                fontSize = 16.sp,
                fontWeight = FontWeight.Bold,
                modifier = Modifier
                    .constrainAs(dialogTitle) {
                        top.linkTo(parent.top, margin = 24.dp)
                        start.linkTo(parent.start)
                        end.linkTo(parent.end)
                    }
            )

            Text(
                text = content,
                color = Color(0xFF969799),
                fontSize = 14.sp,
                modifier = Modifier
                    .constrainAs(dialogContent) {
                        top.linkTo(dialogTitle.bottom, margin = 12.dp)
                        start.linkTo(parent.start)
                        end.linkTo(parent.end)
                    }
            )

            Row(
                modifier = Modifier
                    .fillMaxWidth()
                    .constrainAs (dialogBtnLayout){
                        bottom.linkTo(parent.bottom, margin = 24.dp)
                        start.linkTo(parent.start, margin = 24.dp)
                        end.linkTo(parent.end,24.dp)
                    },
                horizontalArrangement = Arrangement.SpaceAround
            ) {
                TextButton(
                    onClick = onDismissRequest,
                    modifier = Modifier.width(102.dp).height(44.dp).background(Color(0xFF323233),
                        shape = RoundedCornerShape(100.dp)),
                ) {
                    Text(stringResource(R.string.str_delete_dialog_negative), color = Color.White, fontSize = 16.sp, fontWeight = FontWeight.Bold)
                }
                TextButton(
                    onClick = onConfirmation,
                    modifier = Modifier.width(102.dp).height(44.dp).background(
                        brush = Brush.linearGradient(
                            colors = listOf(Color(0xFFFCE9C1), Color(0xFFF3C5B2)), // 起始到结束颜色
                            start = Offset(x = 0f, y = 0f),     // 顶部起始
                            end = Offset(x = 0f, y = Float.POSITIVE_INFINITY) // 底部无限延伸
                        ),
                        shape = RoundedCornerShape(100.dp),
                    ),
                ) {
                    Text(stringResource(R.string.str_delete_dialog_positive), color = Black12, fontSize = 16.sp, fontWeight = FontWeight.Bold)
                }
            }

        }
    }
}